<template>
<view>
	<uni-card :is-shadow="false">
		<uni-section title="事件详情" type="line">
			<uni-section title="事件">
				<template v-slot:right>
					{{ info.warnType?info.warnType:'暂无数据' }}
				</template>
			</uni-section>
			<uni-section title="事件时间">
				<template v-slot:right>
					{{ info.warnTime?getdatatime(info.warnTime):'-' }}
				</template>
			</uni-section>
			<uni-section title="设备">
				<template v-slot:right>
					<view v-for="(item, index) in info.device">
						<uni-card :title="item.deviceName" :is-shadow="false">
							<view class="content">
								<!-- :extra="1" -->
								<view class="card_bottom_view"><span class="card_bottom_span">设备采集值:</span><span>{{ item.concentration }}</span></view>
								<view class="card_bottom_view"><span class="card_bottom_span">检测对象:</span><span>{{ item.detection }}</span></view>
								<view class="card_bottom_view"><span class="card_bottom_span">数据单位:</span><span>{{ item.unit }}</span></view>
								<view class="card_bottom_view"><span class="card_bottom_span">通道信息:</span><span>{{ item.route }}</span></view>
							</view>
						</uni-card>
					</view>
				</template>
			</uni-section>
		</uni-section>
	</uni-card>
	
	<uni-card v-show="show" :is-shadow="false">
		<uni-section title="操作" type="line">
			<uni-forms-item label="整改人" required>
				<uni-data-select v-model="userId" :localdata="userList" @change="userchange" label="请选择" style="width: 90%;margin: 0 auto;"></uni-data-select>
			</uni-forms-item>
			<button class="reject_button" @click="submit">提交</button>
		</uni-section>
	</uni-card>
</view>
</template>

<script>
import {getGeneralUserList, getEventDictList, getEventDetailById, divideEventRectify, getDetectionObjectDictList, getDataUnitDictList,} from "@/api/system/uniapp.js"
	export default {
		data() {
			return {
				deptId: uni.getStorageSync('storage_data').vuex_deptid,
				info: {},
				userList: [],
				monitorList: [],
				dataUnitList: [],
				userId: null,
				createBy: uni.getStorageSync('storage_data').vuex_userId,
				show: true,
			}
		},
		onLoad: function(option) {
			this.info = JSON.parse(option.row)
			// this.geteventCode(this.info.eventCode).then(res => {this.info.eventCode = res})
			this.getEventDetailById()
			this.getGeneralUserList()
		},
		methods: {
			submit(){
				if(!this.userId){
					uni.showToast({title: '请选择整改人！',icon: 'error',duration:2000});
					return false
				}
				uni.showLoading({
					title: '提交中...',
					mask: true
				});
				divideEventRectify({id: this.info.id, rectifier: this.userId, assignor: this.createBy}).then(res => {
					if(res.code == 200){
						uni.$emit('allocation',{msg:'页面更新', index: this.info.index})
						uni.showToast({title: "上报成功!",icon: "success",position: 'bottom'})
						this.show = false;
						uni.hideLoading()
					}else{
						uni.showToast({title: '上报失败！',icon: 'error',duration:2000});
						uni.hideLoading()
					}
				})
			},
			userchange(e){
				this.userId = e
			},
			getEventDetailById(){
				getEventDetailById({id: this.info.id}).then(res => {
					console.log("res", res)
					// res.data.map(i => {
						// this.getmonitorObject(i.monitorObject).then(res => {i.monitorObject = res})
						// this.getdataUnit(i.getdataUnit).then(res => {i.getdataUnit = res})
					// })
					this.info.device = res.data
				})
			},
			getGeneralUserList(){
				getGeneralUserList({deptId: this.deptId}).then(res => {
					res.data.map(i => {
						this.userList.push({ value: i.userId, text: i.nickName })
					})
				})
			},
			async geteventCode(item){
				let data;
				await getEventDictList().then(res => {
					data = res.data
				})
				for(let i = 0;i < data.length;i++){
					if(data[i].code == item){
						return data[i].name
					}
				}
			},
			async getmonitorObject(item){
				if(this.monitorList.length == 0){
					await getDetectionObjectDictList().then(res => {
						this.monitorList = res.data
					})
				}
				for(let i = 0;i < this.monitorList.length;i++){
					if(this.monitorList[i].code == item){
						return this.monitorList[i].name
					}
				}
			},
			async getdataUnit(item){
				await getDataUnitDictList().then(res => {
					this.dataUnitList = res.data
				})
				for(let i = 0;i < this.dataUnitList.length;i++){
					if(this.dataUnitList[i].code == item){
						return this.dataUnitList[i].name
					}
				}
			},
			getdatatime(time, type) {
			  if (!time) {
				return "暂无数据";
			  }
			  const dt = new Date(time);
			  const y = dt.getFullYear();
			  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
			  const d = (dt.getDate() + "").padStart(2, "0");
			  const hh = (dt.getHours() + "").padStart(2, "0");
			  const mm = (dt.getMinutes() + "").padStart(2, "0");
			  const ss = (dt.getSeconds() + "").padStart(2, "0");
			  return `${y}年${m}月${d}日 ${hh}:${mm}:${ss}`;
			},
		}
	}
</script>

<style>

.reject_button{
	background-color: #ecf5ff;
	color: #409eff;
	border: 1px solid #b3d8ff;
	width: 100%;
	font-size: 14px;
	margin: 0 auto;
}
</style>
